﻿Public Class CampaignDesign
    Inherits System.Web.UI.Page
    Private et As New ETModelContainer
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            UpdateCampaignList()

        End If
    End Sub

    Protected Sub cmdNew_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdNew.Click
        Dim camp As Campaign = New Campaign
        camp.CampaignName = CType(Page.Master, IMasterPage).CurrentUserName & "'s new campaign"
        et.Campaigns.AddObject(camp)
        et.SaveChanges()
        UpdateCampaignList()
    End Sub

    Private Sub UpdateCampaignList()

        Dim c = From camp In et.Campaigns
        lstCampaigns.Items.Clear()

        lstCampaigns.DataSource = c
        lstCampaigns.DataTextField = "CampaignName"
        lstCampaigns.DataValueField = "CampaignID"
        lstCampaigns.DataBind()

    End Sub

    Private Sub lstCampaigns_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstCampaigns.SelectedIndexChanged

        Dim camp As Campaign = (From c In et.Campaigns Where c.CampaignID = CInt(lstCampaigns.SelectedValue)).FirstOrDefault

        txtCampaignName.Text = camp.CampaignName


        Dim prods = From p In et.Products Where p.CampaignID = CInt(lstCampaigns.SelectedValue)
        Dim prizes = From pr In et.Prizes Where pr.CampaignID = CInt(lstCampaigns.SelectedValue)

        grdProducts.DataSource = prods.ToList
        grdPrizes.DataSource = prizes.ToList

        grdProducts.DataBind()
        grdPrizes.DataBind()





    End Sub

    Private Sub grdProducts_RowAdded(ByVal sender As Object, ByVal e As Infragistics.Web.UI.GridControls.RowAddedEventArgs) Handles grdProducts.RowAdded

    End Sub

    Private Sub grdProducts_RowAdding(ByVal sender As Object, ByVal e As Infragistics.Web.UI.GridControls.RowAddingEventArgs) Handles grdProducts.RowAdding

    End Sub
End Class